package com.ckr.controller;

import com.ckr.common.lang.Result;
import com.ckr.util.UpPhotoNameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件控制器
 *
 * @author Shadowckr
 * @create 2022-02-12 10:50
 */

@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    UpPhotoNameUtils upPhotoNameUtils;

    @PostMapping("/uploadImg")
    public Result ChangePic(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
        // 这个不需要验证，没必要！
        String userPic = upPhotoNameUtils.SaveUserPic("BlogImg", file);
        System.out.println("upload image...");
        if (userPic == null) {
            Result.success(0);
        }
        return Result.success(userPic);
    }

}
